const Map = {}
const Options = {
  officeNo: [
    {'key': 'CSX510', 'code': 'CSX510', 'cname': 'CSX510'}
  ],
  issueChannel: [ // 出票渠道
    {'key': 'B2B', 'code': 'B2B', 'cname': 'B2B'},
    {'key': 'BSP', 'code': 'BSP', 'cname': 'BSP'},
    {'key': 'BOP', 'code': 'BOP', 'cname': 'BOP'},
    {'key': 'B2C', 'code': 'B2C', 'cname': 'B2C'}
  ],
  orderStatus: [ // 订单状态
    {'key': '4', 'code': 'issueTicket', 'cname': '已出票'},
    {'key': '8', 'code': 'refundAll', 'cname': '全部退票'},
    {'key': '5', 'code': 'cancel', 'cname': '取消'},
    {'key': '3', 'code': 'drawing', 'cname': '出票中'},
    {'key': '2', 'code': 'waitTicket', 'cname': '待出票'},
    {'key': '7', 'code': 'refundPart', 'cname': '部分退票'},
    {'key': '9', 'code': 'issueFailed', 'cname': '出票失败'},
    {'key': '1', 'code': 'waitPay', 'cname': '待支付'},
    {'key': '10', 'code': 'thawFailed', 'cname': '解冻失败'},
    {'key': '6', 'code': 'delete', 'cname': '已删除'}
  ],
  autoIssue: [
    {'key': '0', 'code': 'off', 'cname': '关闭'},
    {'key': '1', 'code': 'on', 'cname': '开启'}
  ],
  passengerStatus: [
    {'key': '0', 'code': 'common1', 'cname': '正常票（不含退票）'},
    {'key': '1', 'code': 'common2', 'cname': '正常票（含退票）'},
    {'key': '2', 'code': 'refund', 'cname': '退票'}
  ]
}

for (let key in Options) {
  const list = Options[key]
  const map = {}
  list.forEach(i => {
    map[i.key] = i
  })
  // 代理get事件，避免map取到null
  Map[key] = new Proxy(map, {
    get: function (target, property) {
      return target[property] || {'key': null, 'code': null, 'cname': null}
    }
  })
}

export default {
  Map: Map,
  Options: Options,
  getOptions (type, codes) {
    return Options[type].filter(i => {
      return codes.indexOf(i.code) > -1
    })
  },
  getByCode (type, code) {
    const list = Options[type].filter(i => {
      return i.code === code
    })
    if (list.length > 0) {
      return list[0]
    } else {
      return {'key': null, 'code': null, 'cname': null}
    }
  }
}
